package com.glsc.ngateway.common.base.converter.flowable;

import com.glsc.ngateway.common.api.flowable.dto.demand.FlowableAssigneeDto;
import com.glsc.ngateway.common.base.domain.mysql.flowable.FlowableAssignee;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class FlowableAssigneeConverter {
    @Nullable
    public static FlowableAssignee dto2Domain(FlowableAssigneeDto dto) {
        return Objects.isNull(dto) ? null : FlowableAssignee.builder()
                .id(dto.getId())
                .processDefinitionKey(dto.getProcessDefinitionKey())
                .taskDefinitionKey(dto.getTaskDefinitionKey())
                .assigneeVariable(dto.getAssigneeVariable())
                .sysid(dto.getSysid())
                .roleName(dto.getRoleName())
                .assigneeName(dto.getAssigneeName())
                .type(dto.getType())
                .build();
    }

    @Nullable
    public static List<FlowableAssignee> dto2Domain(List<FlowableAssigneeDto> dto) {
        return CollectionUtils.isEmpty(dto) ? null: dto.stream().map(FlowableAssigneeConverter::dto2Domain).collect(Collectors.toList());
    }

    @Nullable
    public static FlowableAssigneeDto domain2Dto(FlowableAssignee domain) {
        return Objects.isNull(domain) ? null : FlowableAssigneeDto.builder()
                .id(domain.getId())
                .processDefinitionKey(domain.getProcessDefinitionKey())
                .taskDefinitionKey(domain.getTaskDefinitionKey())
                .assigneeVariable(domain.getAssigneeVariable())
                .sysid(domain.getSysid())
                .roleName(domain.getRoleName())
                .assigneeName(domain.getAssigneeName())
                .type(domain.getType())
                .build();
    }

    @Nullable
    public static List<FlowableAssigneeDto> domain2Dto(List<FlowableAssignee> domain) {
        return CollectionUtils.isEmpty(domain) ? null: domain.stream().map(FlowableAssigneeConverter::domain2Dto).collect(Collectors.toList());
    }
}
